﻿using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Sharp.Portal.Configuration;
using Sharp.Portal.Mvc.Form;
using Sharp.Portal;
using Sharp.Portal.AdminLTE;

namespace Sharp.WebBooter.Areas.Platform
{
    /// <summary>
    /// 系统信息设置
    /// </summary>
    [DisplayName("系统信息设置")]
    [ItemPage(OpenWith = OpenWith.Tile2Column)]
    public class PlatformInfo : ISystemConfig, ISharpForm
    {
        /// <summary>
        /// 平台的系统级
        /// </summary>
        public PlatformInfo()
        {
            EMailConfig = new EMailParam();
            UI = new BSSharpFrom(this);

#if DEBUG
            ClientId = "1234";
            ClientSecret = "5678";
#endif
        }

        [Display(Name = "系统名称")]
        public string SysName => "大平台";

        /// <summary>
        /// 简介
        /// </summary>
        [Display(Name = "简介")]
        public string Description { get; set; }

        /// <summary>
        /// 网址
        /// </summary>
        [Display(Name = "网址")]
        [RegularExpression(@"^http[s]{0,1}://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$", ErrorMessage = "网址 格式不正确")]
        public string WebSite { get; set; }

        /// <summary>
        /// 官方微博
        /// </summary>
        [Display(Name = "官方微博")]
        public string Blog { get; set; }
        /// <summary>
        /// 官方微信
        /// </summary>
        [Display(Name = "官方微信")]
        public string WeChat { get; set; }
        /// <summary>
        /// 官方邮箱
        /// </summary>
        [Display(Name = "官方邮箱")]
        [RegularExpression(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "官方邮箱 格式不正确")]
        public string Email { get; set; }
        /// <summary>
        /// Logo图片
        /// </summary>
        [Display(Name = "Logo图片"), DataType(DataType.Upload)]
        public string LogoUrl { get; set; }


        [Section("电邮服务配置")]
        public EMailParam EMailConfig { get; set; }
        /// <summary>
        /// 使用组织结构树布局
        /// </summary>
        [Display(Name = "组织结构树布局")]
        public bool EnableOrgTreeLayout { get; set; }
        /// <summary>
        /// 客户端Id
        /// </summary>
        [Display(Name = "客户端Id")]
        public string ClientId { get; set; }
        /// <summary>
        /// 客户端密钥
        /// </summary>
        [Display(Name = "客户端密钥")]
        public string ClientSecret { get; set; }
        /// <summary>
        /// 配置文件的文件名
        /// </summary>
        public string ConfigFileName => "平台信息设置.Config";
        /// <summary>
        /// 开发商
        /// </summary>
        public string Developer => "www.PlatformSharp.com";
        [System.Xml.Serialization.XmlIgnore]
        public SharpFrom UI { get; set; }

        /// <summary>
        /// 电邮配置
        /// </summary>
        public class EMailParam
        {
            public EMailParam()
            {
                FromEMail = "ak47@163.com";
                LoginName = "ak47@163.com";
                Password = "ak47";
                SmtpServer = "smtp.163.com";
            }
            /// <summary>
            /// 发送人邮箱
            /// </summary>
            [Display(Name = "发送人邮箱")]
            public string FromEMail { get; set; }
            /// <summary>
            /// 邮件登录名
            /// </summary>
            [Display(Name = "邮件登录名")]
            public string LoginName { get; set; }
            /// <summary>
            /// 邮件登录密码
            /// </summary>
            [Display(Name = "邮件登录密码")]
            public string Password { get; set; }
            /// <summary>
            /// smtp服务器
            /// </summary>
            [Display(Name = "smtp服务器")]
            public string SmtpServer { get; set; }
        }
    }
}